package it.amicosmanettone.finance.stocky.adapter;

import it.amicosmanettone.finance.stocky.R;
import it.amicosmanettone.finance.stocky.bean.SingleStockBean;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapterStockPortfolio extends ArrayAdapter {

	ArrayList<SingleStockBean> singleStockBeanListAdapter = null;
	String numberOfStock;

	public ListAdapterStockPortfolio(Context context, int textViewResourceId,
			ArrayList<SingleStockBean> singleStockBeanList, String numberOfStock) {
		super(context, textViewResourceId, singleStockBeanList);
		this.singleStockBeanListAdapter = singleStockBeanList;
		this.numberOfStock = numberOfStock;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.row_stock_portfolio, null);
		TextView nome = (TextView) convertView.findViewById(R.id.textViewName);
		TextView value = (TextView) convertView.findViewById(R.id.textViewValue);
		ImageView imageStatus = (ImageView) convertView.findViewById(R.id.imageSTATUS);
		
		 String stockCurrency = this.singleStockBeanListAdapter.get(position).getStockCurrency();// Valuta originale di questa stock
		 String stockSymbol = this.singleStockBeanListAdapter.get(position).getStockSymbol();// Stock symbol
		 double stockValue = this.singleStockBeanListAdapter.get(position).getStockValue();// Valore singola azione...
		 long stockNumbers = this.singleStockBeanListAdapter.get(position).getStockNumbers();// Numero di azioni di questo tipo...
		 double stockTrend = this.singleStockBeanListAdapter.get(position).getStockTrend();

		nome.setText(stockSymbol + " : " + stockValue + " " + stockCurrency);
		value.setText(numberOfStock + " " + stockNumbers);
		
		if(stockTrend == 1){
			imageStatus.setBackgroundResource(R.drawable.green_arrow);
		}else if(stockTrend == 0){
			imageStatus.setBackgroundResource(R.drawable.equal);
		}else if(stockTrend < 0){
			imageStatus.setBackgroundResource(R.drawable.red_arrow);
		}
		
		return convertView;
	}

}